package com.dongdong.bookstore.module.ums.service.impl;

import com.dongdong.bookstore.module.ums.model.Admin;
import com.dongdong.bookstore.module.ums.model.AdminLoginLog;
import com.dongdong.bookstore.module.ums.mapper.AdminLoginLogMapper;
import com.dongdong.bookstore.module.ums.service.AdminLoginLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dongdong.bookstore.module.ums.service.UmsCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 管理员登录日志  服务实现类
 * </p>
 *
 * @author chiangkai
 * @since 2021-10-20
 */
@Service
public class AdminLoginLogServiceImpl extends ServiceImpl<AdminLoginLogMapper, AdminLoginLog> implements AdminLoginLogService {

    @Autowired
    private UmsCacheService umsCacheService;

    @Override
    public void addAdminLoginLog(String username, String ipAddress) {
        Admin admin = umsCacheService.getAdmin(username);
        if (admin != null) {
            AdminLoginLog log = new AdminLoginLog();
            log.setAdminId(admin.getId());
            log.setIp(ipAddress);
            baseMapper.insert(log);
        }
    }
}
